package com.shanjupay.common.utilbak;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 配置文件工具类
 */
@Component
public class ConfigUtil {

    private static ConfigUtil instance;

    @Autowired
    private Environment env;

    @PostConstruct
    public void init() {
        instance = this;
    }

    public static String getProperty(String key) {
        return instance.env.getProperty(key);
    }

    public static String getProperty(String key,String defult) {
        String value = null;
        try {
            value = instance.env.getProperty(key);
            if(value == null || "".equals(value)){
                value = defult;
            }
        }catch (Exception e){
            value = defult;
        }
        return value;
    }

}
